package com.esm.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.esm.model.User;
import com.esm.service.FuncService;
import com.esm.serviceimpl.FuncServiceImpl;
import com.esm.utils.PrintWriterUtil;

import net.sf.json.JSONArray;




/**
 * 
 * @author 王文成
 *
 */




public class FuncController extends  HttpServlet{
	private static final long serialVersionUID = 1L;
	FuncService authService = new FuncServiceImpl();
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException 
	{
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException 
	{
		HttpSession session = req.getSession();
		PrintWriter  pw = resp.getWriter();
		int fid = Integer.parseInt(req.getParameter("pid"));
		User currentUser = (User) session.getAttribute("currentUser");
		int rid = currentUser.getRid();
		JSONArray  jao = authService.getRoleAuthorityByRidPid(rid, fid);
		PrintWriterUtil.flushJaoAndClosePrintWriter(pw, jao);
	}
}
